package kduck.example.service.impl;

import com.goldgov.kduck.dao.ParamMap;
import com.goldgov.kduck.dao.query.QuerySupport;
import com.goldgov.kduck.service.DefaultService;
import kduck.example.entity.ApplicantInfo;
import kduck.example.entity.WorkInfo;
import kduck.example.query.WorkQuery;
import kduck.example.service.WorkService;


import com.goldgov.kduck.service.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

@Service
public class WorkServiceImpl extends DefaultService implements WorkService {

    @Override
    public void addApplicant(ApplicantInfo applicantInfo) {
        super.add(CODE_APPLICANT,applicantInfo);
    }

    @Override
    public void addWork(Long aId, WorkInfo workInfo) {
        Assert.notNull(aId,"公司ID不能为null");

        workInfo.setA_ID(aId.toString());

        super.add(CODE_WORK,workInfo);
    }

    @Override
    public void updateWork(WorkInfo workInfo) {
        super.update(CODE_WORK,workInfo);
    }

    @Override
    public void deleteWork(String[] wId) {
        super.delete(CODE_WORK,wId);
    }

    @Override
    public WorkInfo getWork(String wId) {
        return super.getForBean(CODE_WORK,wId,WorkInfo::new);
    }

    @Override
    public List<WorkInfo> listWork(String wName, Page page) {
        Map<String, Object> paramMap = ParamMap.create("W_NAME", wName).toMap();
        QuerySupport query = super.getQuery(WorkQuery.class, paramMap);
        return super.listForBean(query,page,WorkInfo::new);
    }
}
